package VentanaV2;

import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class VentanaV2 extends JFrame implements ActionListener {
	private JPanel jp;
	private JPanel jp2;
	private JTextField jt1;
	private JButton boton;
	private String uno="";
	private String dos="";

	private void inicializar() {
		setTitle("Ventana");
		int ancho = Toolkit.getDefaultToolkit().getScreenSize().width;
		int alto = Toolkit.getDefaultToolkit().getScreenSize().height;
		int tAncho = 250;
		int tAlto = 300;
		setSize(tAncho, tAlto);
		setResizable(false);
		setLocation((ancho / 2) - (tAncho / 2), (alto / 2) - (tAlto / 2));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		this.jp = new JPanel(new GridLayout(1, 1));
		this.add(jp);
		this.jp2 = new JPanel(new GridLayout(2, 2));
		jp.add(jp2);

		this.jt1 = new JTextField();
		jp2.add(jt1);

		boton = new JButton("Segunda palabra");
		jp2.add(boton);

		// Listener
		boton.addActionListener(this);
		boton.setActionCommand("1");

	}

	public VentanaV2() {
		inicializar();
		setVisible(true);
	}

	public static void main(String[] args) {
		new VentanaV2();
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("1")) {
			uno=jt1.getText();
			boton.setText("concatenar");
			boton.setActionCommand("2");
			jt1.setText("");
		} else if (e.getActionCommand().equals("2")) {
			boton.setText("Fin");
			dos=jt1.getText();
			jt1.setText(uno+dos);
			boton.setActionCommand("3");
			boton.setEnabled(false);
		} 
	}
}